package com.fit.pages.classes;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.AnonymousAccess;
import com.fit.annotations.ProfessorAccess;
import com.fit.annotations.StudentAccess;
import com.fit.dao.homework.HomeworkDAO;
import com.fit.dao.user.UserDAO;
import com.fit.entities.homework.Homework;
import com.fit.entities.user.User;
import com.fit.model.MD5;
import com.fit.pages.ErrorPage;

@AdminAccess
@AnonymousAccess
@ProfessorAccess
@StudentAccess
public class Edit {

	@Property
	@Persist
	private Homework homework;
	@Inject
	private HomeworkDAO homeworkDAO;
	@InjectPage
	private ErrorPage errorPage;
	@Property
	private String newPassword;

//	Object onActivate(Long id) {
//		user = userDAO.findByID(id);
//		if (user == null) {
//			errorPage.setMessage("Greska prilikom prikaza zapisa korisnika! ");
//			return errorPage;
//		}
//		return null;
//	}
//
//	Object onSuccess() {
//		try {
//
//			if (newPassword != null) {
//				newPassword = MD5.md5(newPassword);
//				if (newPassword.equals(user.getPassword())) {
//					user.setPassword((newPassword));
//				}
//			}
//			userDAO.update(user);
//			return Browse.class;
//		} catch (Exception e) {
//			errorPage.setMessage("Greska prilikom brisanja zapisa korisnika! ");
//			return errorPage;
//		}
//
//	}

}
